package ru.budget.mobile.domain.usecase.income

import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.flow
import ru.budget.mobile.core.Response
import ru.budget.mobile.core.ResponseStates
import ru.budget.mobile.domain.entities.IncomeDomain
import ru.budget.mobile.domain.repository.IncomeRepository
import ru.budget.mobile.ui.entities.IncomeUI

class AddIncomeUseCase(
    private val repository: IncomeRepository
) {

    operator fun invoke(income: IncomeUI): Flow<Response<Boolean>> = flow {
        emit(Response.Loading(state = ResponseStates.LOADING))
        emit(repository.addIncome(
            income = IncomeDomain(
                id = income.id,
                sum = income.sum,
                datetime = income.datetime
            )
        ))
    }
}